package com.djzhou.gmms.util.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.StrutsStatics;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

public class SessionInterceptor implements Interceptor{

	private static final long serialVersionUID = -520686124206452492L;

	public void destroy() {
		
		
	}

	public void init() {
		
		
	}

	public String intercept(ActionInvocation invocation) throws Exception {
		ActionContext actionContext = invocation.getInvocationContext(); 
		HttpServletRequest request= (HttpServletRequest) actionContext.get(StrutsStatics.HTTP_REQUEST);
		HttpServletResponse response=(HttpServletResponse)actionContext.get(StrutsStatics.HTTP_RESPONSE);
		if(request.getSession().getAttribute("sessionUser")==null){
			response.sendRedirect(request.getContextPath()+"/");
			request.getSession().invalidate();
			return null;
		}
		return invocation.invoke();
	}

}
